require("common-css");
require("local_index-css");
require("swiper-css");

import {
  loader
} from "hobbit";
import {
  GetHotNews
} from "request";
import {
  initCommon
} from "common";
const template = require("template");

const app = {
  init() {
    app.currNum = 2;
    initCommon();
    this.bind();

    var mySwiper = new Swiper('.swiper-container', {
      loop: true,
      // 如果需要分页器
      pagination: '.swiper-pagination',
    })
  },
  bind() {
    //加载更多
    $('.see-more').on('click', function() {
      loader.show({
        text: "加载中..."
      });
      app.loadMore();
    });


    var bannerWidth = $(".little_banner ul li").width();
    var liLength = $(".little_banner ul li").length;
    $(".little_banner ul").width( bannerWidth * liLength + 15 + "px" );

    
  },
  loadMore() {
    var params = {};
    params.pageIndex = app.currNum;
    params.hotType = 1;
    params.pageSize = 10;
    GetHotNews(params, (res) => {
      if (res.hasValue == "true") {
        if (res.data) {
          $("#j-product").append(template("goods-list-temp", {
            list: res.data
          }));
        }
        if (res.data.length < 10) {
          $('.see-more').hide();
        }
        app.currNum++;
      } else {
        $('.see-more').hide();
      }
      loader.close();
    });
  }
}
app.init();